
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import storage from './utils/storage'

// 创建应用实例
const app = createApp(App)

// 全局axios配置
axios.defaults.baseURL = import.meta.env.VITE_API_URL || 'http://localhost:3000/api'
axios.interceptors.response.use(
    response => response.data,
    error => {
        console.error('API Error:', error)
        return Promise.reject(error)
    }
)

// 挂载插件
app.use(router)
app.config.globalProperties.$http = axios // 全局注入
app.use(ElementPlus)
app.config.globalProperties.$storage = storage

// 全局注册所有图标
Object.entries(ElementPlusIconsVue).forEach(([key, component]) => {
    app.component(key, component)
})

// 启动应用
app.mount('#app')
